package com.cm.sys.intermanager.controller;

import com.cm.sys.framework.aop.NotCheckIP;
import com.cm.sys.framework.aop.NotCheckLogin;
import com.cm.sys.framework.application.ApiResponseCode;
import com.cm.sys.framework.application.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import java.util.List;
import java.util.Map;

/**
 * name:
 * Description:
 * Created by jhx on 2019/12/26
 */
@Controller
@RequestMapping("/front")
public class GetPushInfoController {

    @Value("${pushUrl}")
    private String pushUrl;

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/getPush")
    @NotCheckLogin
    @NotCheckIP
    @ResponseBody
    public ResponseResult getPush(@RequestBody Map<String,List> map) {
        if (map != null && !map.isEmpty()) {
            try {
               restTemplate.postForEntity(pushUrl, map,String.class);
            } catch (RestClientException e) {
                e.printStackTrace();
                return new ResponseResult(ApiResponseCode.CONNECT_ERROR);
            }
            return new ResponseResult(ApiResponseCode.CONNECT_SUCCESS);
        }else {
            return new ResponseResult(ApiResponseCode.PARAM_NEED);
        }
    }


    @PostMapping("/close")
    @NotCheckLogin
    @NotCheckIP
    @ResponseBody
    public void close(@RequestBody Map<String,List> map){
        try {
            restTemplate.postForEntity(pushUrl, map,String.class);
        } catch (RestClientException e) {
            e.printStackTrace();
        }
    }

}
